package com.cskaoyan.controller;

import com.cskaoyan.bean.data.PageData;
import com.cskaoyan.bean.data.TopicDetailData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.data.PageData;
import com.cskaoyan.model.MarketTopic;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.SystemService;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx/topic")
public class WxTopicController {
    @Autowired
    TopicService topicService;
    @Autowired
    GoodsService goodsService;
    @Autowired
    SystemService systemService;

    @GetMapping("list")
    public BaseRespVo list() {
        List<MarketTopic> marketTopics = topicService.list(1, 10);
        PageData data = PageData.list(marketTopics);
        return BaseRespVo.ok(data);
    }

    @GetMapping("detail")
    public BaseRespVo detail(int id) {
        TopicDetailData data = topicService.queryById(id);
        return BaseRespVo.ok(data);
    }

    @GetMapping("related")
    public BaseRespVo related(int id) {
        Map<String, String> systemConfig = systemService.toMap();
        int limit = Integer.parseInt(systemConfig.get("market_wx_index_topic"));
        PageData data = topicService.queryRelatedList(id, 1, limit);
        return BaseRespVo.ok(data);
    }
}
